package org.onion.pattern.kit.validation.annotation;

import org.onion.pattern.kit.validation.annotation.validator.IsBizCodeValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 业务代码: 由字母,数字,下划线,中划线组成
 * ^[a-zA-Z0-9_-]*$
 *
 */
@Documented
@Constraint(validatedBy = {IsBizCodeValidator.class})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(IsBizCode.IsBizCodeList.class)
public @interface IsBizCode {

    String message() default "代码无效";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface IsBizCodeList {
        IsBizCode[] value();
    }

}
